"""
dict1 = dict([('a','A'),['b','B',]])
print(dict1)

dict2 = dict(name='zs', age=18)
print(dict2)

"""

"""
# dict.fromkeys
dict_keys = ['math','english','sport']
defult_score = 0
score_dict = dict.fromkeys(dict_keys,defult_score)
print(score_dict)  # {'math': 0, 'english': 0, 'sport': 0}

"""

"""
s = {'s':i * 2 for i in range(4)}
print(s)
s2 = {key: value for key,value in [('a','A'),('b','B')]}
print(s2)

s3 = {'a':1, 'b':2, 'c': 3}
print(s3.items())  # dict_items([('a', 1), ('b', 2), ('c', 3)])
print(s3.keys()) # dict_keys(['a', 'b', 'c'])
print(s3.values()) # dict_values([1, 2, 3])
print(s3.fromkeys('aa','66'))
print(dict.fromkeys(['a','b','c'], [1,2,3]))

"""


"""
person = {"name": "Alice", "age": 30}

# 使用另一个字典更新
person.update({"age": 31, "city": "Beijing"})
print(person) # {'name': 'Alice', 'age': 31, 'city': 'Beijing'}

# 使用键值对序列更新
person.update([("job", "Engineer"), ("country", "China")])
print(person) # 添加了 job 和 country 
# {'name': 'Alice', 'age': 31, 'city': 'Beijing', 
# 'job': 'Engineer', 'country': 'China'}

# 使用关键字参数更新
person.update(salary=50000, department="IT")
print(person) # 添加了 salary 和 department

"""

"""
from collections import defaultdict, OrderedDict

# defaultdict - 为不存在的键提供默认值
word_count = defaultdict(int)  # 默认值为0
word_count["apple"] += 1
print(word_count["apple"])  # 1
print(word_count["banana"]) # 0 (不会报错)
print(word_count)

# OrderedDict - 保持插入顺序（Python 3.7+ 普通字典已支持）
ordered = OrderedDict()
ordered["a"] = 1
ordered["b"] = 2
ordered["c"] = 3
print(list(ordered.keys())) # ['a', 'b', 'c']

"""

# 字典合并
"""
d1 = {'a': 'a', 'b': 'b', 'c': 'c'}
d2 = {'a':'A'}
d3 = d2 | d1 
d4 = d1 | d2
print(d3)
print(d2)
print(d4)

"""

d = {'a':'A'}
# print(d['B']) 报错
# print(d.get('B')) None
d.setdefault('B',"b")
print(d)
d['c'] = 'C'
print(d)
